package com.wb3.meta.api.core.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wb3.meta.api.core.dao.CustomerToysMapper;
import com.wb3.meta.api.core.dao.ToysChatMsgsMapper;
import com.wb3.meta.api.core.model.ToysChatMsgs;
import com.wb3.meta.api.core.service.ToysChatMsgsService;
import com.wb3.meta.api.core.vo.ReqCustomerToysVo;
import com.wb3.meta.api.core.vo.ReqToysChatMsgsVo;
import com.wb3.meta.api.core.vo.ResCustomerToysVo;
import com.wb3.meta.api.core.vo.ResToysChatMsgsVo;
import com.wb3.meta.common.authentication.RequestHolder;
import com.wb3.meta.common.enums.EnumConstants;
import com.wb3.meta.common.mybatis.DataTableUtil;
import com.wb3.meta.common.pojo.ResultT;
import com.wb3.meta.config.utils.BaichuanUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Slf4j
@Service("toysChatMsgsService")
@Transactional(transactionManager = "dataSourceTransactionManagerOne", rollbackFor = Exception.class)
public class ToysChatMsgsServiceImpl implements ToysChatMsgsService {
    @Autowired
    private ToysChatMsgsMapper toysChatMsgsMapper;


    /**
     * 分页查询方法
     *
     * @param vo
     * @return
     */
    @Override
    public Page<ResToysChatMsgsVo> getModelPage(ReqToysChatMsgsVo vo) {

        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());

        return (Page<ResToysChatMsgsVo>) getModelListByConditions(vo);
    }

    /**
     * 列表查询方法 -返回 res 对象
     *
     * @param vo
     * @return
     */
    @Override
    public List<ResToysChatMsgsVo> getModelListByConditions(ReqToysChatMsgsVo vo) {
        return toysChatMsgsMapper.getModelListByConditions(vo);
    }

    /**
     * 根据条件查询单条数据方法，返回res vo类
     *
     * @param vo
     * @return
     */
    @Override
    public ResToysChatMsgsVo getResModelByConditions(ReqToysChatMsgsVo vo) {
        return toysChatMsgsMapper.getResModelByConditions(vo);
    }

    /**
     * 根据条件查询单个对象方法
     *
     * @param toysChatMsgs
     * @return
     */
    @Override
    public ToysChatMsgs getModelByConditions(ToysChatMsgs toysChatMsgs) {
        return null;
    }

    /**
     * 根据id查询单个对象方法
     *
     * @param id
     * @return
     */
    @Override
    public ToysChatMsgs getModelById(Object id) {
        return toysChatMsgsMapper.selectByPrimaryKey(id);
    }

    /**
     * 新增对象方法
     *
     * @param toysChatMsgs
     */
    @Override
    public void addModel(ToysChatMsgs toysChatMsgs) {
        toysChatMsgs.setCreateTime(new Date());
        toysChatMsgs.setStatus(EnumConstants.StatusEnum.VALID.getCode());
        toysChatMsgsMapper.insertUseGeneratedKeys(toysChatMsgs);
    }

    /**
     * 更新对象方法
     *
     * @param toysChatMsgs
     */
    @Override
    public void updateModel(ToysChatMsgs toysChatMsgs) {
        toysChatMsgs.setUpdateTime(new Date());
        toysChatMsgsMapper.updateByPrimaryKeySelective(toysChatMsgs);
    }

    /**
     * 根据id删除对象方法
     *
     * @param id
     */
    @Override
    public void deleteModelById(Object id) {

    }

    /**
     * 获取分页数据，返回 map对象方法
     *
     * @param vo
     * @return
     */
    @Override
    public ResultT getModelMapPage(ReqToysChatMsgsVo vo) {
        if (vo.getUserChatListId() == null) {
            return ResultT.fail("聊天id不能为空");
        }
        vo.setUserId(RequestHolder.getUserId());
        return ResultT.success(DataTableUtil.changePage(getModelPage(vo)));
    }

    /**
     * 根据id查询单个对象方法，返回 map对象方法
     *
     * @param id
     * @return
     */
    @Override
    public ResultT getModelMapById(Object id) {
        return null;
    }

    /**
     * 根据条件查询单个对象，返回map对象方法
     *
     * @param toysChatMsgs
     * @return
     */
    @Override
    public ResultT getModelMapByConditions(ToysChatMsgs toysChatMsgs) {
        return null;
    }

    /**
     * 查询列表-map对象
     *
     * @param vo
     * @return
     */
    @Override
    public ResultT getResModelListMapByConditions(ReqToysChatMsgsVo vo) {
        return ResultT.success(toysChatMsgsMapper.getModelListByConditions(vo));
    }

    /**
     * 根据条件查询res vo对象，返回map对象方法
     *
     * @param vo
     * @return
     */
    @Override
    public ResultT getResModelMapByConditions(ReqToysChatMsgsVo vo) {
        return null;
    }

    /**
     * 更新或插入对象方法
     *
     * @param vo
     * @return
     */
    @Override
    public ResultT saveOrUpdate(ReqToysChatMsgsVo vo) {
        if (vo.getId() != null) {
            updateModel(vo);
        } else {
            addModel(vo);
        }
        return ResultT.success(vo);
    }

    /**
     * 根据条件删除方法
     *
     * @param vo
     * @return
     */
    @Override
    public ResultT delete(ReqToysChatMsgsVo vo) {
        return null;
    }


}
